package functionroots;

import functionroots.methods.Bissection;
import functionroots.methods.IntervalData;
import functionroots.primitives.RealFunction;
import functionroots.primitives.RootFinder;
import functionroots.samples.Function23;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {

    public static void main(String[] args) {
        RootFinder probe;
        RealFunction f;
        float a = 1, b = 3;
        double x;
        try {
            f = new Function23();
            probe = new Bissection(f, 1e-6);
            x = 0.80180;
            //System.out.println(x - f.value(x)/f.derivative(x));
            //System.out.println(f.value(x));
            /*System.out.println("f(" + a + ") = " + f.value(a));
            System.out.println("f(" + b + ") = " + f.value(b));
            System.out.println("f(" + 1.399871826171875 + ") = " + f.value(1.399871826171875));*/
            /*x = probe.scan(new IntervalData(a, b));
            System.out.println("Estimated root for cossine in interval [" + a
                    + ", " + b + "] is " + x);
            System.out.println(probe.getFunction().value(x));

            a = 3; b = 7;
            probe.setFunction(RealFunction.sine);
            x = probe.scan(new IntervalData(a, b));
            System.out.println("Estimated root for arcsine in interval [" + a
                    + ", " + b + "] is " + x);*/

            x = probe.scan(new IntervalData(a, b));
            System.out.print("Estimated root for function ");
            System.out.print(" is ");
            System.out.println(x);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Bissection.class.getName()).log(Level.SEVERE,
                    null, ex);
        }
    }
}
